<template>
  <el-container  class="container">
    <!--侧边栏-->
    <div class="aside">
      <el-aside width="200px">
        <SideMenu></SideMenu>
      </el-aside>
    </div>

    <el-container>
      <!--顶部导航-->
      <el-header style="background-color:#FFE4E1;height: 6vh">
        <el-row type="flex" >
      <!--标题-->
          <el-col offset="6">
            <span style="font-size: 25px;font-weight: bold;" >吃 了 么</span>
          </el-col>
          <el-col :span="16" style="margin-top: 10px">
            <v-mini-weather></v-mini-weather>
          </el-col>
          <el-col :span="2">
<!--            <v-mini-weather></v-mini-weather>-->
            <div class="header-menu">
              <el-dropdown>
                <span class="el-dropdown-link">
                  <img src="../../assets/img/header/img.png">
                </span>
                <el-dropdown-menu slot="dropdown" >
                  <el-dropdown-item @click.native="addTabs_dropDownMenu({name:'userCenter',title:'个人中心'})">
                    个人中心
                  </el-dropdown-item>
                  <el-dropdown-item @click.native="addTabs_dropDownMenu({name:'myWallet',title:'我的钱包'})">
                    我的钱包
                  </el-dropdown-item>
                  <el-dropdown-item @click.native="logout" divided>退出</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
        </el-row>

      </el-header>

      <!--路由跳转区域-->
      <el-main style="padding: 0;height: 100vh">
        <Tabs></Tabs>
        <div>
          <router-view></router-view>
        </div>
      </el-main>

    </el-container>
  </el-container>

</template>


<script>
import SideMenu from "./layout/SideMenu";
import Tabs from "./layout/Tabs"
/**
 * 引入cookie.js中的removeToken()方法
 */

import {setToken} from "@/utils/cookie";
import {getUserInformation, removeUserInformation} from "@/api/user";
import axios from "axios";


import { vMiniWeather } from 'vue-mini-weather'
import {setWeatherInformation} from "@/api/weather";

export default {
  name: "Home",
  components:{
    SideMenu,Tabs,vMiniWeather
  },
  data() {
    return {
      userName: '',

      //请求返回的参数格式
      weather:{
        city:null,
        wea:null
      },
    }
  },
  methods: {
    /**
     * 退出登录(跳回至登录界面，并清空token信息）
     */
    logout() {
        setToken(false);
        removeUserInformation();
        this.$router.push("/login");
    },
    /**
     * 点击下拉框添加标签页并跳转路由
     */
    addTabs_dropDownMenu(item) {
      this.$router.push("/index/"+item.name);
      this.$store.commit("addTab",item);
    }
  },
  created() {
    const user=JSON.parse(decodeURI(getUserInformation()));
    this.userName=user['userName'];
  },

  mounted() {
    axios.get("https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=25115816%20&appsecret=Qu9Iw9jQ")
    .then(response => {
      this.weather = response.data
      setWeatherInformation(this.weather.wea);
    });

  },

  destroyed() {
    setWeatherInformation(this.weather.wea);
  }
}
</script>

<style lang="less">
.el-container {
  padding: 0;
  margin: 0;
  height: 100vh;
}

.el-header {
  background-color: #FFFFF0;
  color: #FFFFF0;
  text-align: center;

  /**
  1vh：占屏幕1%的位置
   */
  height: 6vh;
  line-height: 6vh;
}

.aside {
  background-color: #ffffff;
  height: 100vh;
}

.el-main {
  background-color: #F0F8FF;
  color: #000;
  height: 100vh;
  padding: 0;
}
.header-menu{
  float: right;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-top: 10px;
}
.el-dropdown-link{
  cursor: pointer;
}

.el-dropdown{
  color: #333;
}

//.el-aside {
//  height: 100vh;
//}

.el-dropdown-link{
  cursor: pointer;
}

.el-link{
  color:#333;
}

a {
  text-decoration: none;
}

img{
  width: 50px;
  height: 50px;
}

</style>
